﻿/*
 *开票公司登录配置js
 *
 */

//上传初始化
function InitUpload() {

    //判断是否支持
    if (!WebUploader.Uploader.support()) {
        var error = "上传控件不支持您的浏览器！请尝试升级flash版本或者使用Chrome引擎的浏览器。<a target='_blank' href='http://se.360.cn'>下载页面</a>";
        if (window.console) {
            window.console.log(error);
        }
        alert(error);
        return;
    }
    var bcid = $("#BcId").val();
    //前台登录Logo上传
    var uploader_FrontLoginLogo = WebUploader.create({
        pick: "#filePicker_FrontLoginLogo",
        auto: true,
        swf: '/components/webuploader/Uploader.swf',
        server: '/tool/upload?operation=upload_bcompany_loginimage&bcid=' + bcid,
        fileVal: 'upload',
        accept: {
            title: 'Images',
            extensions: 'jpg,jpeg,png',
            mimeTypes: 'image/jpg,image/jpeg,image/png'
        },
        fileSingleSizeLimit: 2 * 1024 * 1024,
        resize: false
    });
    uploader_FrontLoginLogo.on('uploadSuccess', function (file, response) {
        var success = response.success;
        if (success) {
            var div_image = '<div filepath_origin="' + response.data.filepath_origin + '" class="thumbnail">' +
                '<a href="' + response.data.filepath_big + '" target="_blank">' +
                '<img src="' + response.data.filepath_small + '">' +
                '</a>'
            '</div>';
            $("#fileList_FrontLoginLogo").html(div_image);
            $("#FrontLoginLogo").val(response.data.filepath_origin);
        } else {
            alert(response.info);
        }

    });
    uploader_FrontLoginLogo.on('uploadError', function (file) {
        alert("上传失败");
    });
    //前台登录背景图片上传
    var uploader_FrontLoginBackgroundImage = WebUploader.create({
        pick: "#filePicker_FrontLoginBackgroundImage",
        auto: true,
        swf: '/components/webuploader/Uploader.swf',
        server: '/tool/upload?operation=upload_bcompany_loginimage&bcid=' + bcid,
        fileVal: 'upload',
        accept: {
            title: 'Images',
            extensions: 'jpg,jpeg,png',
            mimeTypes: 'image/jpg,image/jpeg,image/png'
        },
        fileSingleSizeLimit: 2 * 1024 * 1024,
        resize: false
    });

    uploader_FrontLoginBackgroundImage.on('uploadSuccess', function (file, response) {
        var success = response.success;
        if (success) {
            var div_image = '<div filepath_origin="' + response.data.filepath_origin + '" class="thumbnail">' +
                '<a href="' + response.data.filepath_big + '" target="_blank">' +
                '<img src="' + response.data.filepath_small + '">' +
                '</a>' +
                '</div>';
            $("#fileList_FrontLoginBackgroundImage").html(div_image);
            $("#FrontLoginBackgroundImage").val(response.data.filepath_origin);
        } else {
            alert(response.info);
        }
    });
    uploader_FrontLoginBackgroundImage.on('uploadError', function (file) {
        alert("上传失败");
    });

    //后台登录Logo上传
    var uploader_BackLoginLogo = WebUploader.create({
        pick: "#filePicker_BackLoginLogo",
        auto: true,
        swf: '/components/webuploader/Uploader.swf',
        server: '/tool/upload?operation=upload_bcompany_loginimage&bcid=' + bcid,
        fileVal: 'upload',
        accept: {
            title: 'Images',
            extensions: 'jpg,jpeg,png',
            mimeTypes: 'image/jpg,image/jpeg,image/png'
        },
        fileSingleSizeLimit: 2 * 1024 * 1024,
        resize: false
    });
    uploader_BackLoginLogo.on('uploadSuccess', function (file, response) {
        var success = response.success;
        if (success) {
            var div_image = '<div filepath_origin="' + response.data.filepath_origin + '" class="thumbnail">' +
                '<a href="' + response.data.filepath_big + '" target="_blank">' +
                '<img src="' + response.data.filepath_small + '">' +
                '</a>' +
                '</div>';
            $("#fileList_BackLoginLogo").html(div_image);
            $("#BackLoginLogo").val(response.data.filepath_origin);
        } else {
            alert(response.info);
        }
    });
    uploader_BackLoginLogo.on('uploadError', function (file) {
        alert("上传失败");
    });
    //后台登录背景图片上传
    var uploader_BackLoginBackgroundImage = WebUploader.create({
        pick: "#filePicker_BackLoginBackgroundImage",
        auto: true,
        swf: '/components/webuploader/Uploader.swf',
        server: '/tool/upload?operation=upload_bcompany_loginimage&bcid=' + bcid,
        fileVal: 'upload',
        accept: {
            title: 'Images',
            extensions: 'jpg,jpeg,png',
            mimeTypes: 'image/jpg,image/jpeg,image/png'
        },
        fileSingleSizeLimit: 2 * 1024 * 1024,
        resize: false
    });

    uploader_BackLoginBackgroundImage.on('uploadSuccess', function (file, response) {
        var success = response.success;
        if (success) {
            var div_image = '<div filepath_origin="' + response.data.filepath_origin + '" class="thumbnail">' +
                '<a href="' + response.data.filepath_big + '" target="_blank">' +
                '<img src="' + response.data.filepath_small + '">' +
                '</a>' +
                '</div>';
            $("#fileList_BackLoginBackgroundImage").html(div_image);
            $("#BackLoginBackgroundImage").val(response.data.filepath_origin);
        } else {
            alert(response.info);
        }
    });
    uploader_BackLoginBackgroundImage.on('uploadError', function (file) {
        alert("上传失败");
    });
}

//保存登录配置
function saveLoginConfig() {
    //前台登录logo
    var FrontLoginLogo = $("#FrontLoginLogo").val();
    if (FrontLoginLogo == undefined || FrontLoginLogo == '') {
        alert("请选择前台登录logo");
        return false;
    }

    //前台登录背景图
    var FrontLoginBackgroundImage = $("#FrontLoginBackgroundImage").val();
    if (FrontLoginBackgroundImage == undefined || FrontLoginBackgroundImage == '') {
        alert("请选择前台登录背景图");
        return false;
    }

    //后台登录logo
    var BackLoginLogo = $("#BackLoginLogo").val();
    if (BackLoginLogo == undefined || BackLoginLogo == '') {
        alert("请选择后台登录logo");
        return false;
    }

    //后台登录背景图
    var BackLoginBackgroundImage = $("#BackLoginBackgroundImage").val();
    if (BackLoginBackgroundImage == undefined || BackLoginBackgroundImage == '') {
        alert("请选择后台登录背景图");
        return false;
    }

    //验证通过，提交表单
    document.forms[0].submit();
}

(function Init() {
    //初始化上传控件
    InitUpload();
})();